package com.book.controller;


import com.book.config.JwtUtil;
import com.book.pojo.Reward;
import com.book.service.RewardService;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fk
 * @since 2023-10-16 08:24:19
 */
@RestController
@RequestMapping("/reward")
public class RewardController {

    @Autowired
    private RewardService rewardService;

    @Autowired
    private JwtUtil jwtUtil;

    @PostMapping("addReward")
    public int addReward(@RequestHeader String unauthorized, Reward reward){
        //从token中解析用户id
        Claims claims = jwtUtil.parseJwt(unauthorized);
        Long userId = Long.valueOf(claims.getId());
        Reward reward1 = reward.setId(userId);
        return rewardService.addReward(reward1);
    }

}
